<?php
require 'includes/config.php';
require 'includes/auth.php';
require 'includes/sanitize.php';
$data = sanitize($_GET);
$message = "default";
if (isset($data['submit']) && isset($data['name'])) {
	// Request to backend to get info about the league
	$request = new makeRequest($backend.'api.php?method=league&name='.$data['name'], 'GET');
	$tmp = $request->makeRequest();
	$rbody = $tmp[0];
	$obj = json_decode($rbody);
	$http_code = $tmp[1];
	// Check so there is no errors
	if($http_code == 200 && $obj[0]->{'name'} != ""){
		$message = '<a href="viewleague.php?id='.$obj[0]->{'id'}.'">Go to league '.$obj[0]->{'name'}.'</a>';

	}else{
		$message = "No league found";
	}
}

require 'includes/header.php';
require 'includes/topmenu.php';
echo '<div id=kaka>';
require 'includes/sidemenu.php';
echo '<div id="content">';
/* Content shown on page */
if($message != "default"){
	echo $message;
}
?>
<p>Search for a league:</p>
<table>
	<form method="get" action="<?php echo $PHP_SELF; ?>">
	<tr>
		<td>League name:<br />
		</td>
		<td><input type="text" name="name" value="<?php echo $name; ?>" /><br />
		</td>
	</tr>
	<tr>
		<td><input type="submit" Value="Search" name="submit" />
	
	</form>
	</td>
	<td></td>
	</tr>
</table>
<?php

require 'includes/footer.php';
?>